package com.example.onlinemusic.controller;

import com.example.onlinemusic.model.HomePage;
import com.example.onlinemusic.model.User;
import com.example.onlinemusic.tools.Constant;
import com.example.onlinemusic.tools.ResponseBodyMessage;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("/api")
public class curUserController {
    // 从session中获取用户信息给前端
    @RequestMapping("/currentUser")
    public ResponseBodyMessage<User> getCurrentUser(HttpSession session) {
        User user = (User) session.getAttribute(Constant.USERINFO_SESSION_KEY);
        if (user != null) {
            return new ResponseBodyMessage<>(0, "成功", user);
        } else {
            return new ResponseBodyMessage<>(-1, "用户未登录");
        }
    }

}
